#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <sched.h>
#include <stdio.h>

int main()
{
  cpu_set_t set;
  sched_getaffinity(0,sizeof(cpu_set_t),&set);
  
  for (int i = 0; i < 10; i++) {
    if(CPU_ISSET(i,&set))
      printf("CPU %d is set\n",i);
    else
      printf("CPU %d is unset\n",i);
  }

  CPU_ZERO(&set);
  CPU_SET(1,&set);
  CPU_CLR(0,&set);
  if(sched_setaffinity(0,sizeof(cpu_set_t),&set) != 0)
    printf("sche_setaffinity failed\n");

  for (int i = 0; i < 10; i++) {
    if(CPU_ISSET(i,&set))
      printf("CPU %d is set\n",i);
    else
      printf("CPU %d is unset\n",i);
  }
  return 0;
}
